import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/api_money_amount.dart';
import 'package:backend.core/core/domain/entities/web/web_money_amount.dart';

const kApiMoneyAmountValueKey = 'value';
const kApiMoneyAmountCurrencyKey = 'currency';

class ApiMoneyAmountDto extends Equatable {
  const ApiMoneyAmountDto._internal({
    required this.value,
    required this.currency,
  });

  final String value;
  final String currency;

  @override
  List<Object?> get props {
    return [
      value,
      currency,
    ];
  }

  factory ApiMoneyAmountDto.fromApiMoneyAmount(ApiMoneyAmount apiMoneyAmount) {
    return ApiMoneyAmountDto._internal(
      value: apiMoneyAmount.value,
      currency: apiMoneyAmount.currency,
    );
  }

  factory ApiMoneyAmountDto.fromMoneyAmount(WebMoneyAmount moneyAmount) {
    return ApiMoneyAmountDto._internal(
      value: moneyAmount.value,
      currency: moneyAmount.currency,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiMoneyAmountValueKey: value,
      kApiMoneyAmountCurrencyKey: currency,
    };
  }
}
